//
//  BaseViewController.swift
//  BUYOU
//
//  Created by tyuu on 2024/5/29.
//

import UIKit

import EmptyDataSet_Swift
import YYText

class BaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        view.backgroundColor = .white
    }
    
    // 列表视图
    lazy var tableView: UITableView = {
        let table = UITableView(frame: .zero, style: .plain)
        table.separatorStyle = .none
        table.backgroundColor = .clear
        table.estimatedSectionHeaderHeight = 0
        table.estimatedSectionFooterHeight = 0
        table.showsVerticalScrollIndicator = false
        table.showsHorizontalScrollIndicator = false
        table.emptyDataSetSource = self
        table.emptyDataSetDelegate = self
        table.automaticallyAdjustsScrollIndicatorInsets = false
        return table
    }()
    
    lazy var collectionView: UICollectionView = {
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: getCollectionViewLayout())
        collectionView.backgroundColor = .clear
        collectionView.showsVerticalScrollIndicator = false
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.emptyDataSetSource = self
        collectionView.emptyDataSetDelegate = self
        collectionView.automaticallyAdjustsScrollIndicatorInsets = false
        return collectionView
    }()

    // 配置 collectionViewLayout
    func getCollectionViewLayout() -> UICollectionViewLayout {
        return UICollectionViewFlowLayout()
    }

}

extension BaseViewController: EmptyDataSetSource, EmptyDataSetDelegate {
    
    /// ================Source========================
    // 配置图片
    func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
        return UIImage(named: "")
    }
    
    // 配置标题
    func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        let attr = NSMutableAttributedString.init(string: "暂无数据哦")
        attr.yy_color = .init(hexString: "#aaaaaa")
        attr.yy_font = .boldSystemFont(ofSize: 14)
        return attr
    }
    
   
    // 配置间隙
    func spaceHeight(forEmptyDataSet scrollView: UIScrollView) -> CGFloat {
        return 30.0
    }
    
 
    
    /// ================Delegate========================
    // 控制显示
    func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -> Bool {
        return true
    }
    
    // 控制滚动
    func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool {
        return true
    }
    
    // 控制点击
    func emptyDataSetShouldAllowTouch(_ scrollView: UIScrollView) -> Bool {
        return true
    }

}
